Revert "GdkDrop: drop the priv struct"
authorMatthias Clasen <mclasen@redhat.com>
Sun, 15 Jul 2018 19:41:20 +0000 (15:41 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Sun, 15 Jul 2018 19:58:05 +0000 (15:58 -0400)
This reverts commit d927c3bee0f169279d86e13756c5ba4f6cba94e4.

I was wrong. Better to hide the struct fields from subclasses.

gdk/gdkdrop.c
gdk/gdkdropprivate.h

index 1f1a9e137c54f9f2c3e224e0d9d0dcbe297cd060..03bc1e2485ac0d4f6219233e1a8aa614248145c9 100644 (file)
 #include "gdkpipeiostreamprivate.h"
 #include "gdksurface.h"
 
+typedef struct _GdkDropPrivate GdkDropPrivate;
+
+struct _GdkDropPrivate {
+  GdkDevice *device;
+  GdkDrag *drag;
+  GdkContentFormats *formats;
+  GdkSurface *surface;
+  GdkDragAction actions;
+};
+
 enum {
   PROP_0,
   PROP_ACTIONS,
@@ -47,7 +57,7 @@ enum {
 
 static GParamSpec *properties[N_PROPERTIES] = { NULL, };
 
-G_DEFINE_ABSTRACT_TYPE (GdkDrop, gdk_drop, G_TYPE_OBJECT)
+G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (GdkDrop, gdk_drop, G_TYPE_OBJECT)
 
 /**
  * GdkDrop:
@@ -84,6 +94,7 @@ gdk_drop_read_local_async (GdkDrop             *self,
                            GAsyncReadyCallback  callback,
                            gpointer             user_data)
 {
+  GdkDropPrivate *priv = gdk_drop_get_instance_private (self);
   GdkContentFormats *content_formats;
   const char *mime_type;
   GTask *task;
@@ -92,7 +103,7 @@ gdk_drop_read_local_async (GdkDrop             *self,
   g_task_set_priority (task, io_priority);
   g_task_set_source_tag (task, gdk_drop_read_local_async);
 
-  if (self->drag == NULL)
+  if (priv->drag == NULL)
     {
       g_task_return_new_error (task, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
                                      _("Drag'n'drop from other applications is not supported."));
@@ -100,7 +111,7 @@ gdk_drop_read_local_async (GdkDrop             *self,
       return;
     }
 
-  content_formats = gdk_content_provider_ref_formats (self->drag->content);
+  content_formats = gdk_content_provider_ref_formats (priv->drag->content);
   content_formats = gdk_content_formats_union_serialize_mime_types (content_formats);
   mime_type = gdk_content_formats_match_mime_type (content_formats, formats);
 
@@ -111,7 +122,7 @@ gdk_drop_read_local_async (GdkDrop             *self,
 
       stream = gdk_pipe_io_stream_new ();
       output_stream = g_io_stream_get_output_stream (stream);
-      gdk_drag_write_async (self->drag,
+      gdk_drag_write_async (priv->drag,
                                     mime_type,
                                     output_stream,
                                     io_priority,
@@ -155,6 +166,7 @@ gdk_drop_set_property (GObject      *gobject,
                        GParamSpec   *pspec)
 {
   GdkDrop *self = GDK_DROP (gobject);
+  GdkDropPrivate *priv = gdk_drop_get_instance_private (self);
 
   switch (prop_id)
     {
@@ -163,26 +175,26 @@ gdk_drop_set_property (GObject      *gobject,
       break;
 
     case PROP_DEVICE:
-      self->device = g_value_dup_object (value);
-      g_assert (self->device != NULL);
-      if (self->surface)
-        g_assert (gdk_surface_get_display (self->surface) == gdk_device_get_display (self->device));
+      priv->device = g_value_dup_object (value);
+      g_assert (priv->device != NULL);
+      if (priv->surface)
+        g_assert (gdk_surface_get_display (priv->surface) == gdk_device_get_display (priv->device));
       break;
 
     case PROP_DRAG:
-      self->drag = g_value_dup_object (value);
+      priv->drag = g_value_dup_object (value);
       break;
 
     case PROP_FORMATS:
-      self->formats = g_value_dup_boxed (value);
-      g_assert (self->formats != NULL);
+      priv->formats = g_value_dup_boxed (value);
+      g_assert (priv->formats != NULL);
       break;
 
     case PROP_SURFACE:
-      self->surface = g_value_dup_object (value);
-      g_assert (self->surface != NULL);
-      if (self->device)
-        g_assert (gdk_surface_get_display (self->surface) == gdk_device_get_display (self->device));
+      priv->surface = g_value_dup_object (value);
+      g_assert (priv->surface != NULL);
+      if (priv->device)
+        g_assert (gdk_surface_get_display (priv->surface) == gdk_device_get_display (priv->device));
       break;
 
     default:
@@ -198,31 +210,32 @@ gdk_drop_get_property (GObject    *gobject,
                        GParamSpec *pspec)
 {
   GdkDrop *self = GDK_DROP (gobject);
+  GdkDropPrivate *priv = gdk_drop_get_instance_private (self);
 
   switch (prop_id)
     {
     case PROP_ACTIONS:
-      g_value_set_flags (value, self->actions);
+      g_value_set_flags (value, priv->actions);
       break;
 
     case PROP_DEVICE:
-      g_value_set_object (value, self->device);
+      g_value_set_object (value, priv->device);
       break;
 
     case PROP_DISPLAY:
-      g_value_set_object (value, gdk_device_get_display (self->device));
+      g_value_set_object (value, gdk_device_get_display (priv->device));
       break;
 
     case PROP_DRAG:
-      g_value_set_object (value, self->drag);
+      g_value_set_object (value, priv->drag);
       break;
 
     case PROP_FORMATS:
-      g_value_set_boxed (value, self->formats);
+      g_value_set_boxed (value, priv->formats);
       break;
 
     case PROP_SURFACE:
-      g_value_set_object (value, self->surface);
+      g_value_set_object (value, priv->surface);
       break;
 
     default:
@@ -235,9 +248,10 @@ static void
 gdk_drop_finalize (GObject *object)
 {
   GdkDrop *self = GDK_DROP (object);
+  GdkDropPrivate *priv = gdk_drop_get_instance_private (self);
 
-  g_clear_object (&self->device);
-  g_clear_object (&self->drag);
+  g_clear_object (&priv->device);
+  g_clear_object (&priv->drag);
 
   G_OBJECT_CLASS (gdk_drop_parent_class)->finalize (object);
 }
@@ -362,9 +376,11 @@ gdk_drop_init (GdkDrop *self)
 GdkDisplay *
 gdk_drop_get_display (GdkDrop *self)
 {
+  GdkDropPrivate *priv = gdk_drop_get_instance_private (self);
+
   g_return_val_if_fail (GDK_IS_DROP (self), NULL);
 
-  return gdk_device_get_display (self->device);
+  return gdk_device_get_display (priv->device);
 }
 
 /**
@@ -378,9 +394,11 @@ gdk_drop_get_display (GdkDrop *self)
 GdkDevice *
 gdk_drop_get_device (GdkDrop *self)
 {
+  GdkDropPrivate *priv = gdk_drop_get_instance_private (self);
+
   g_return_val_if_fail (GDK_IS_DROP (self), NULL);
 
-  return self->device;
+  return priv->device;
 }
 
 /**
@@ -395,9 +413,11 @@ gdk_drop_get_device (GdkDrop *self)
 GdkContentFormats *
 gdk_drop_get_formats (GdkDrop *self)
 {
+  GdkDropPrivate *priv = gdk_drop_get_instance_private (self);
+
   g_return_val_if_fail (GDK_IS_DROP (self), NULL);
 
-  return self->formats;
+  return priv->formats;
 }
 
 /**
@@ -411,9 +431,11 @@ gdk_drop_get_formats (GdkDrop *self)
 GdkSurface *
 gdk_drop_get_surface (GdkDrop *self)
 {
+  GdkDropPrivate *priv = gdk_drop_get_instance_private (self);
+
   g_return_val_if_fail (GDK_IS_DROP (self), NULL);
 
-  return self->surface;
+  return priv->surface;
 }
 
 /**
@@ -435,22 +457,26 @@ gdk_drop_get_surface (GdkDrop *self)
 GdkDragAction
 gdk_drop_get_actions (GdkDrop *self)
 {
+  GdkDropPrivate *priv = gdk_drop_get_instance_private (self);
+
   g_return_val_if_fail (GDK_IS_DROP (self), 0);
 
-  return self->actions;
+  return priv->actions;
 }
 
 void
 gdk_drop_set_actions (GdkDrop       *self,
                       GdkDragAction  actions)
 {
+  GdkDropPrivate *priv = gdk_drop_get_instance_private (self);
+
   g_return_if_fail (GDK_IS_DROP (self));
   g_return_if_fail ((actions & GDK_ACTION_ASK) == 0);
 
-  if (self->actions == actions)
+  if (priv->actions == actions)
     return;
 
-  self->actions = actions;
+  priv->actions = actions;
 
   g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_ACTIONS]);
 }
@@ -469,9 +495,11 @@ gdk_drop_set_actions (GdkDrop       *self,
 GdkDrag *
 gdk_drop_get_drag (GdkDrop *self)
 {
+  GdkDropPrivate *priv = gdk_drop_get_instance_private (self);
+
   g_return_val_if_fail (GDK_IS_DROP (self), 0);
 
-  return self->drag;
+  return priv->drag;
 }
 
 /**
@@ -529,7 +557,9 @@ gdk_drop_read_internal (GdkDrop             *self,
                         GAsyncReadyCallback  callback,
                         gpointer             user_data)
 {
-  if (self->drag)
+  GdkDropPrivate *priv = gdk_drop_get_instance_private (self);
+
+  if (priv->drag)
     {
       gdk_drop_read_local_async (self,
                                  formats,
@@ -678,6 +708,7 @@ gdk_drop_read_value_internal (GdkDrop             *self,
                               GAsyncReadyCallback  callback,
                               gpointer             user_data)
 {
+  GdkDropPrivate *priv = gdk_drop_get_instance_private (self);
   GdkContentFormatsBuilder *builder;
   GdkContentFormats *formats;
   GValue *value;
@@ -690,11 +721,11 @@ gdk_drop_read_value_internal (GdkDrop             *self,
   g_value_init (value, type);
   g_task_set_task_data (task, value, free_value);
 
-  if (self->drag)
+  if (priv->drag)
     {
       GError *error = NULL;
 
-      if (gdk_content_provider_get_value (self->drag->content, value, &error))
+      if (gdk_content_provider_get_value (priv->drag->content, value, &error))
         {
           g_task_return_pointer (task, value, NULL);
           g_object_unref (task);
@@ -875,13 +906,14 @@ gdk_drop_emit_enter_event (GdkDrop  *self,
                            gboolean  dont_queue,
                            guint32   time)
 {
+  GdkDropPrivate *priv = gdk_drop_get_instance_private (self);
   GdkEvent *event;
 
   event = gdk_event_new (GDK_DRAG_ENTER);
-  event->any.surface = g_object_ref (self->surface);
+  event->any.surface = g_object_ref (priv->surface);
   event->dnd.drop = g_object_ref (self);
   event->dnd.time = time;
-  gdk_event_set_device (event, self->device);
+  gdk_event_set_device (event, priv->device);
 
   gdk_drop_do_emit_event (event, dont_queue);
 }
@@ -893,15 +925,16 @@ gdk_drop_emit_motion_event (GdkDrop  *self,
                             double    y_root,
                             guint32   time)
 {
+  GdkDropPrivate *priv = gdk_drop_get_instance_private (self);
   GdkEvent *event;
 
   event = gdk_event_new (GDK_DRAG_MOTION);
-  event->any.surface = g_object_ref (self->surface);
+  event->any.surface = g_object_ref (priv->surface);
   event->dnd.drop = g_object_ref (self);
   event->dnd.time = time;
   event->dnd.x_root = x_root;
   event->dnd.y_root = y_root;
-  gdk_event_set_device (event, self->device);
+  gdk_event_set_device (event, priv->device);
 
   gdk_drop_do_emit_event (event, dont_queue);
 }
@@ -911,13 +944,14 @@ gdk_drop_emit_leave_event (GdkDrop  *self,
                            gboolean  dont_queue,
                            guint32   time)
 {
+  GdkDropPrivate *priv = gdk_drop_get_instance_private (self);
   GdkEvent *event;
 
   event = gdk_event_new (GDK_DRAG_LEAVE);
-  event->any.surface = g_object_ref (self->surface);
+  event->any.surface = g_object_ref (priv->surface);
   event->dnd.drop = g_object_ref (self);
   event->dnd.time = time;
-  gdk_event_set_device (event, self->device);
+  gdk_event_set_device (event, priv->device);
 
   gdk_drop_do_emit_event (event, dont_queue);
 }
@@ -929,15 +963,16 @@ gdk_drop_emit_drop_event (GdkDrop  *self,
                           double    y_root,
                           guint32   time)
 {
+  GdkDropPrivate *priv = gdk_drop_get_instance_private (self);
   GdkEvent *event;
 
   event = gdk_event_new (GDK_DROP_START);
-  event->any.surface = g_object_ref (self->surface);
+  event->any.surface = g_object_ref (priv->surface);
   event->dnd.drop = g_object_ref (self);
   event->dnd.time = time;
   event->dnd.x_root = x_root;
   event->dnd.y_root = y_root;
-  gdk_event_set_device (event, self->device);
+  gdk_event_set_device (event, priv->device);
 
   gdk_drop_do_emit_event (event, dont_queue);
 }
index 6d049239851e30de7571ffae512ba8faaccc4fe4..86a1fdbf8aa834c38ee0ca1618e8f3f249b81afd 100644 (file)
@@ -34,12 +34,6 @@ typedef struct _GdkDropClass GdkDropClass;
 
 struct _GdkDrop {
   GObject parent_instance;
-
-  GdkDevice *device;
-  GdkDrag *drag;
-  GdkContentFormats *formats;
-  GdkSurface *surface;
-  GdkDragAction actions;
 };
 
 struct _GdkDropClass {